package com.heima.jedis.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisConnectionFactory {
    private final static JedisPool jedisPool;
    static {
        //配置连接池
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        //设置连接池中最大连接数为8
        poolConfig.setMaxTotal(8);
        //设置连接池中最大空闲连接数为8
        poolConfig.setMaxIdle(8);
        //设置连接池中最少空闲连接数为0
        poolConfig.setMinIdle(0);
        //设置获取连接时的最大等待时间为 1000 毫秒
        poolConfig.setMaxWaitMillis(1000);
        //创建连接对象
        jedisPool = new JedisPool(poolConfig, "192.168.12.128",
                6379,1000,"123321");
    }
    public static Jedis getJedis(){
        return jedisPool.getResource();
    }
}
